package com.zyk.scaffold.seata.stock.business.stock.service.impl;

import com.zyk.scaffold.common.utils.AssertUtil;
import com.zyk.scaffold.seata.stock.business.stock.pojo.request.StockRequest;
import com.zyk.scaffold.seata.stock.business.stock.service.StockService;
import com.zyk.scaffold.seata.stock.repositorys.mapper.StockTblMapper;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
public class StockServiceImpl implements StockService {

    @Resource
    private StockTblMapper stockTblMapper;

    @Override
    @GlobalTransactional
    public Boolean ok(StockRequest stockRequest) {
        return stockTblMapper.consumeStock(stockRequest) > 0;
    }

    @Override
    @GlobalTransactional
    public Boolean error(StockRequest stockRequest) {
        Boolean aBoolean = stockTblMapper.consumeStock(stockRequest) > 0;
        AssertUtil.error("减库存失败！");
        return aBoolean;
    }

    @Override
    @Transactional
    public Boolean none_seata_ok(StockRequest stockRequest) {
        return stockTblMapper.consumeStock(stockRequest) > 0;
    }

    @Override
    @Transactional
    public Boolean none_seata_error(StockRequest stockRequest) {
        Boolean aBoolean = stockTblMapper.consumeStock(stockRequest) > 0;
        AssertUtil.error("减库存失败！");
        return aBoolean;
    }
}
